﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@* 工序管理新增页面 *@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo</title>
</head>
<body class="layui-padding-3">
    <h3 style="color: #34c38f">
        <i class="layui-icon layui-icon-left" style="color: #dcccc0"></i><a style="color: #dcccc0;cursor:pointer" onclick="location.href='/produceplan/produceplanList'"> 返回&nbsp;&nbsp;</a><span style="color: #000">|</span>&nbsp;&nbsp;主生产计划&nbsp;<span style="color: #000">(状态码)</span>
    </h3>
    <hr style="color: #34c38f" />
    <div class="layui-form-item">
        <div class="layui-input-block">
            <label class="layui-form-label">计划编码:</label>
            <input type="text"
                   id="produceplanNumber"
                   lay-verify="required"
                   autocomplete="off"
                   class="layui-input"
                   style="width: 400px" />
        </div>
    </div>
    <div style="margin-left: 600px; margin-top: -50px">
        <div class="layui-input-block">
            <label class="layui-form-label">计划名称:</label>
            <input type="text"
                   id="produceplanName"
                   lay-verify="required"
                   autocomplete="off"
                   class="layui-input"
                   style="width: 400px" />
        </div>
    </div>
    <br />
    <br />
    <div class="layui-form-item">
        <div class="layui-input-block">
            <label class="layui-form-label">计划描述:</label>
            <textarea placeholder="请输入内容" id="produceplanDetail" class="layui-textarea" style="width:400px;height:70px"></textarea>
        </div>
    </div>

    <div style="margin-left: 600px; margin-top: -50px">
        <div class="layui-input-block">
            <label class="layui-form-label">状态:</label>
            <select name="interest" lay-filter="aihao" style="width: 400px" id="produceplanStatus" disabled>
                <option value=1 selected>新建</option>
                <option value=2>变更</option>
                <option value=3>确认</option>
                <option value=4>取消</option>
            </select>
        </div>
    </div>
    <br />
    <br />
    <div>
        <div class="layui-input-block">
            <label class="layui-form-label">制单人:</label>
            <input type="text"
                   id="MakeName"
                   lay-verify="required"
                   autocomplete="off"
                   class="layui-input"
                   style="width: 400px" />
        </div>
    </div>
    <div style="margin-left: 600px; margin-top: -50px">
        <div class="layui-input-block">
            <label class="layui-form-label">制单部门:</label>
            <select name="WorkCenter" id="MakeDepartment" lay-filter="aihao" style="width: 400px">
                <option value="0">请选择</option>
                <option value=1>开发部</option>
                <option value=2>管理部</option>
                <option value=3>外交部</option>
            </select>
        </div>
    </div>
    <br />
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 1000px"
                    type="submit"
                    class="layui-btn"
                    lay-submit
                    id="Save"
                    lay-filter="demo1"
                    onclick="ProducePlanAdd()">
                保存<i class="layui-icon layui-icon-list"></i>
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 1000px"
                    type="button"
                    class="layui-btn"
                    id="Status"
                    onclick="ChangeStatus()"
                    >
                提交<i class="layui-icon layui-icon-right"></i>
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left:820px;margin-top:-100px"
                    type="button"
                    class="layui-btn layui-bg-orange"
                    lay-submit
                    onclick="ChangeAudit()"
                    id="Audit">
                
                审核通过<i class="layui-icon layui-icon-list"></i>
            </button>
        </div>
        
       
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 820px;margin-top:-100px"
                    type="button"
                    class="layui-btn layui-bg-red"
                    id="Overrule"
                    onclick="ChangeAlert()">
                驳回<i class="layui-icon layui-icon-list"></i>
            </button>
        </div>
        </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 1000px;margin-top:-100px"
                    type="button"
                    class="layui-btn"
                    id="Alter"
                    onclick="ChangeAlert()">
                变更<i class="layui-icon layui-icon-list"></i>
            </button>
        </div>
    </div>
    <h3 style="color: #50a5f1">所需资源行</h3>
    <hr />
    <h4>行信息</h4>
    <div class="layui-btn-container">
        <button style="margin-left: 1100px"
                type="button"
                class="layui-btn layui-bg-blue"
                lay-on="ProducePlan-custom">
            <span><i class="layui-icon layui-icon-addition"></i>新增资源</span>
        </button>
    </div>


    <script>
        //新增
        function ProducePlanAdd() {
            var data = {
                produceplanNumber: $("#produceplanNumber").val(),
                produceplanName: $("#produceplanName").val(),
                produceplanDetail: $("#produceplanDetail").val(),
                produceplanStatus: $("#produceplanStatus").val(),
                MakeName: $("#MakeName").val(),
                MakeDepartment: $("#MakeDepartment").val(),
            }
            console.log(data)
            $.post({
                url: '@ViewBag.RBACWrite' + "/api/produceplan/produceplanAdd",
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 1) {
                        layer.alert("新增成功");
                        localStorage.setItem("produceplanNumber", $("#produceplanNumber").val())
                        localStorage.setItem("produceplanAudit", 0)

                        return;
                    }
                    else {
                        layer.alert("新增失败");
                        return;
                    }
                }
            })
        }
        //审批(提交)
        function ChangeStatus() {
            localStorage.setItem("SubmitStatus", 1);
            var SubmitStatus = localStorage.getItem("SubmitStatus")
                    var data = {
                produceplanNumber: localStorage.getItem("produceplanNumber"),
                changeNum: SubmitStatus,
            }
            console.log(data)
            $.post({
                url: '@ViewBag.RBACWrite' + "/api/produceplan/produceplanApproval",
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        layer.alert("提交成功");
                        $('#Status').hide();
                        $('#Save').hide();
                            $('#Audit').show();
                        $('#Overrule').show();
                        return;
                    }
                    else {
                        layer.alert("提交失败");
                        return;
                    }
                }
            })
        }
        //审核（审核通过）
        function ChangeAudit() {
            localStorage.setItem("SubmitStatus", 2);
            var SubmitStatus = localStorage.getItem("SubmitStatus")
            var data = {
                produceplanNumber: localStorage.getItem("produceplanNumber"),
                changeNum: SubmitStatus,
            }
            console.log(data)
            $.post({
                url: '@ViewBag.RBACWrite' + "/api/produceplan/produceplanApproval",
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        layer.alert("审核成功");
                        $('#Status').hide();
                        $('#Save').hide();
                        $('#Audit').hide();
                        $('#Overrule').hide();
                        $("#Alter").show()
                        return;
                    }
                    else {
                        layer.alert("提交失败");
                        return;
                    }
                }
            })
        }
        //审核（变更）
        function ChangeAlert() {
            localStorage.setItem("SubmitStatus", 0);
            var SubmitStatus = localStorage.getItem("SubmitStatus")
            var data = {
                produceplanNumber: localStorage.getItem("produceplanNumber"),
                changeNum: SubmitStatus,
            }
            console.log(data)
            $.post({
                url: '@ViewBag.RBACWrite' + "/api/produceplan/produceplanApproval",
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        $('#Status').show();
                        $('#Save').show();
                        $('#Audit').hide();
                        $('#Overrule').hide();
                        $('#Alter').hide();
                        return;
                    }
                    else {
                        return;
                    }
                }
            })
        }
        //关闭页面操作
        window.onbeforeunload = function () {
            localStorage.clear("produceplanAudit");
        };
    </script>
    <table class="layui-hide" id="ID-table-demo-search"></table>
    <script>

        layui.use(['table', 'jquery'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;
            var $ = layui.jquery;
            //弹出层
            util.on('lay-on', {
                'ProducePlan-custom': function () {
                    layer.open({
                        type: 2,
                        title: '资源行添加',
                        shadeClose: true,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['900px', '600px'],
                        content: '/produceplan/LayoutAdd',
                        end: function () { // 弹出层关闭后执行的回调
                            formData.produceplanNumber = $("#produceplanNumber").val(),
                                $('#Status').show();
                                Seach()
                        },
                    });
                },
            });
            var formData = {
                produceplanNumber: ""
            };
            if (formData.produceplanNumber != "") {
                Seach();
            }
            //按钮条件显示
            var condition = localStorage.getItem("produceplanAudit")
            form.render('select');
            if (condition!= 0) {
                $('#Status').hide();
            }
            var SubmitStatus = localStorage.getItem("SubmitStatus")
            if (SubmitStatus != 1) {
                $('#Audit').hide();
                $('#Overrule').hide();
            }
            var SubmitStatus = localStorage.getItem("SubmitStatus")
            if (SubmitStatus != 2) { 
                $("#Alter").hide()
            }

            // 提交事件
            form.on('submit(search)', function (data) {
                var field = data.field; // 获取表单字段值
                // 显示填写结果，仅作演示用
                formData.produceplanNumber = $("#produceplanNumber").val()
                Seach();
                return false; // 阻止默认 form 跳转
            });


            // 搜索提交
            function Seach() {
                console.log(formData);
                var WareNum = '@ViewBag.RBACWrite' + "/api/produceplan/produceDetailsList?produceplanNumber=" + formData.produceplanNumber;
                $.ajax({
                    url: WareNum,
                    type: 'get',
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [
                                [
                                    { field: 'produceDetailsId', title: '行号', width: 80 },
                                    { field: 'chooseId', title: '物料编码', width: 120 },
                                    { field: 'chooseName', title: '物料名称', width: 120 },
                                    { field: 'unit', title: '单位', width: 100 },
                                    { field: 'specification', title: '规格', width: 100 },
                                    { field: 'chooseAttributeName', title: '物料属性', width: 100 },
                                    { field: 'bomVersionName', title: 'Bom版本', width: 100 },
                                    { field: 'planCount', title: '计划数量', width: 100 },
                                    { field: 'startDateTime', title: '开工日期	', width: 100 },
                                    { field: 'remark', title: '完工日期	', width: 100 },
                                    { field: 'processDetailStateName', title: '摘要	', width: 100 },
                                    {
                                        fixed: 'right',
                                        title: '操作',
                                        width: 134,
                                        minWidth: 125,
                                        templet: '#toolDemo',
                                    },
                                ],
                            ],
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };
        });
    </script>
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
          <a onclick="" style="color:cornflowerblue;">编辑</a>
          <br />
          <a onclick="" style="color:red">删除</a>
        </div>
    </script>
</body>
</html>
